﻿//
//  GNS_SceneMgr.cpp
//  MobileManage
//
//  Created by mr.l on 16/1/25.
//
//

#include "GNS_SceneMgr.h"
#include "GNS_HallScene.h"
#include "GNS_LoginScene.h"
USING_NS_CC;

Scene * GNS_SceneMgr::replaceScene(ENUM_Scene sceneVal)
{
    auto scene = _mapScene.at(sceneVal);
    if (scene==nullptr) {
        switch (sceneVal) {
            case SCENE_LOGIN:
            {
                scene = GNS_LoginScene::createScene();
                _mapScene.insert(SCENE_LOGIN, scene);
                break;
            }
            case SCENE_HALL:
            {
                scene = GNS_HallScene::createScene();
				_mapScene.insert(SCENE_HALL, scene);
            }
            default:
                break;
        }
	}
	auto transition = TransitionPageTurn::create(0, scene, false);
    Director::getInstance()->replaceScene(transition);
    if (_curScene !=nullptr && scene!=_curScene) {
        std::vector<int> mapKeyVec;
        mapKeyVec = _mapScene.keys();//获取所有 Key 值
        for(auto key:mapKeyVec)
        {
            auto selscene = _mapScene.at(key);
            if (selscene==_curScene) {
                selscene =nullptr;
                _mapScene.erase(key);
                break;
            }
        }
    }
    _curScene =scene;
    return _curScene;
}
Layer * GNS_SceneMgr::AddSceneLayer(ENUM_Layer layerVal)
{
    auto layer = _mapLayer.at(layerVal);
    if (layer == nullptr) {
        switch (layerVal) {
            case LAYER_HALL:
            {
                layer = GNS_HallScene::create();
				_mapLayer.insert(LAYER_HALL, layer);
            }
                break;
			case LAYER_LOGIN:
            {
				layer = GNS_LoginScene::create();
				_mapLayer.insert(LAYER_LOGIN, layer);
            }
                break;
            default:
                break;
        }
    }
    if (_curLayer !=nullptr && layer!=_curLayer) {
        std::vector<int>mapKeyVec;
        mapKeyVec = _mapLayer.keys();
        for (auto key:mapKeyVec) {
            auto sellayer = _mapLayer.at(key);
            if (sellayer ==_curLayer) {
                _mapLayer.erase(key);
                break;
            }
        }
    }
    
    _curLayer =layer;
    return _curLayer;
}